<template>
	<view class="home">
		<input type="text" v-model="title" placeholder="请输入标题"></input>
		<uni-file-picker 
			v-model="imageValue" 
			fileMediatype="image"
			ref="files"
			mode="grid" 
			@select="select" 
			@progress="progress" 
			@success="success" 
			@fail="fail" 
		/>
		<button @click="onsubmit">上传文件</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imageValue:[],
				filesUrl:[],
				title:""
			}
		},
		onLoad() {

		},
		methods: {
			onsubmit(){
				this.addPicDemoRow()
			},
			// upload(){
			// 	this.$refs.files.upload()
			// },
			// 获取上传状态
			select(e){
				console.log('选择文件：',e)
			},
			// 获取上传进度
			progress(e){
				console.log('上传进度：',e)
			},
			
			// 上传成功
			success(e){
				console.log('上传成功',e)
				this.filesUrl=e.tempFilePaths
				console.log(this.filesUrl)
			},
			
			// 上传失败
			fail(e){
				console.log('上传失败：',e)
			},
			
			// 向数据库添加一条数据
			addPicDemoRow(){
				uniCloud.callFunction({
					name:"add_fileUrl_row",
					data:{
						title:this.title,
						filesUrl:this.filesUrl
					}
				}).then(e=>{
					console.log(e)
				})
			}
			
		}
	}
</script>

<style>
	
</style>
